﻿<script type="text/javascript">
    $(function () {
        getButton("loginlog");
    });

    function ui_loginlog_init_list(toolbar) {
        $("#ui_loginlog_dg").datagrid({       //初始化datagrid
            url: "ashx/rm_loginlog.ashx?action=search",
            striped: true, rownumbers: true, pagination: true, pageSize: 20,
            idField: 'id',
            sortName: 'loginDate',
            sortOrder: 'desc',
            pageList: [20, 40, 60, 80, 100],
            frozenColumns: [[
                { field: 'ck', checkbox: true },
                {
                    width: 100,
                    title: '登陆名',
                    field: 'userName',
                    sortable: true,
                    formatter: function (value, row, index) {
                        return value.length > 10 ? '<span title="' + value + '">' + value + '</span>' : value;
                    }
                }
            ]],
            columns: [[
                       { field: 'userIp', title: '登陆IP', sortable: true, width: 100 },
                       { field: 'city', title: '登陆城市', sortable: true, width: 100 },
                       {
                           field: 'success', title: '登陆成功', sortable: true, width: 80, align: 'center',
                           formatter: function (value, row, index) {
                               return value ? '<img src="themes/icons/chk_checked.gif" alt="登陆成功" title="登陆成功" />' : '<img src="themes/icons/delete.gif" alt="登陆失败" title="登陆失败" />';
                           }
                       },
                       { field: 'loginDate', title: '登陆时间', sortable: true, width: 130 }
            ]],
            toolbar: toolbar.length == 0 ? null : toolbar
            //toolbar: [{
            //    text: '导出',
            //    iconCls: 'icon-export',
            //    handler: function () { ui_loginlog_export(); }
            //}, {
            //    text: '删除',
            //    iconCls: 'icon-remove',
            //    handler: function () { ui_loginlog_delete(); }
            //}]
        });
    }
    function ui_loginlog_export() {
        $.show_warning("提示", "登陆日志导出功能暂未实现");
    }
    function ui_loginlog_delete() {
        var rows = $("#ui_loginlog_dg").datagrid("getChecked");
        if (rows.length < 1) {
            $.show_warning("提示", "请先勾选要删除的日志");
            return;
        }
        $.messager.confirm('提示', '确定删除勾选的这' + rows.length + '条日志？', function (r) {
            if (r) {
                para = {};
                para.action = "delete";
                para.timespan = new Date().getTime();

                var ids = [];
                $.each(rows, function (i, row) {
                    ids.push(row.id);
                });
                para.ids = ids.join(",");
                $.ajax({
                    url: "ashx/rm_loginlog.ashx",
                    data: para,
                    type: "POST",
                    dataType: "json",
                    success: function (data) {
                        if (data.success) {
                            $.show_warning("提示", "删除成功！");
                            $("#ui_loginlog_dg").datagrid("reload").datagrid('clearSelections').datagrid('clearChecked');
                        } else {
                            $.show_warning("提示", data.msg);
                        }
                    }
                });
            }
        });
    }
    function ui_loginlog_searchdata() {
        var whereStr = "1=1";
        
        var uname= $('#ui_loginlog_search').find('[name=ui_loginlog_username]').val();
        var ip= $('#ui_loginlog_search').find('[name=ui_loginlog_userip]').val();
        var city = $('#ui_loginlog_search').find('[name=ui_loginlog_city]').val();
        var success = $('#ui_loginlog_search').find('[name=ui_loginlog_success]').val();
        var stime = $('#ui_loginlog_search').find('[name=ui_loginlog_logindatestart]').val();
        var etime = $('#ui_loginlog_search').find('[name=ui_loginlog_logindateend]').val();
        
        if (uname != "") {
            whereStr += " and userName='" + uname + "'";
        }
        if (ip != "") {
            whereStr += " and userIp='" + ip + "'";
        }
        if (city != "") {
            whereStr += " and city='" + city + "'";
        }
        if (success != "select" && success != "") {
            whereStr += " and success=" + success + "";
        }
        
        if (stime != "") {
            whereStr += " and loginDate>'" + stime + "'";
        }
        if (etime != "") {
            whereStr += " and loginDate<'" + etime + "'";
        }

        $("#ui_loginlog_dg").datagrid('load', { where: whereStr});
        $("#ui_loginlog_dg").datagrid('clearSelections').datagrid('clearChecked');
        //$('#ui_loginlog_layout').layout('collapse', 'east');    //隐藏
    }
    function ui_loginlog_cleardata() {
        $('#ui_loginlog_search input').val('');
        $('#ui_loginlog_search select').val('select');
        $('#ui_loginlog_logindatestart').datebox('setValue', '');
        $('#ui_loginlog_logindateend').datebox('setValue', '');
        $("#ui_loginlog_dg").datagrid('load', {});

        $("#ui_loginlog_dg").datagrid('clearSelections').datagrid('clearChecked');
        //$('#ui_loginlog_layout').layout('collapse', 'east');    //隐藏
    }
</script>
<div id="ui_loginlog_layout" class="easyui-layout" data-options="fit:true,border:false">
    <div data-options="region:'east',split:true,border:true,collapsed:true" title="多条件查询"
        style="width: 280px;">
        <div id="ui_loginlog_search">
            <table class="tableForm" style="width: 100%; height: 100%; background: #F5F5F5;">
                <tr>
                    <th>登陆名：
                    </th>
                    <td>
                        <input name="ui_loginlog_username"  class="easyui-textbox"  autocomplete="off" style="width: 130px;" />
                    </td>
                </tr>
                <tr>
                    <th>登陆IP：
                    </th>
                    <td>
                        <input name="ui_loginlog_userip"  class="easyui-textbox"  autocomplete="off" style="width: 130px;" />
                    </td>
                </tr>
                <tr>
                    <th>登陆城市：
                    </th>
                    <td>
                        <input name="ui_loginlog_city"  class="easyui-textbox"  autocomplete="off" style="width: 130px;" />
                    </td>
                </tr>
                <tr>
                    <th>登陆成功：
                    </th>
                    <td>
                        <select name="ui_loginlog_success"  class="easyui-combobox" data-options="panelHeight:65,editable:false" >
                            <option value="select">请选择</option>
                            <option value="1">是</option>
                            <option value="0">否</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <th>登陆时间：
                    </th>
                    <td>
                        <input name="ui_loginlog_logindatestart" id="ui_loginlog_logindatestart" class="easyui-datebox"
                            editable="false" style="width: 140px;" />
                    </td>
                </tr>
                <tr>
                    <th>至：
                    </th>
                    <td>
                        <input name="ui_loginlog_logindateend" id="ui_loginlog_logindateend" class="easyui-datebox"
                            editable="false" style="width: 140px;" />
                    </td>
                </tr>
                <tr>
                    <td>
                        <a href="javascript:void(0);" class="easyui-linkbutton" iconcls="icon-search" plain="true"
                            onclick="ui_loginlog_searchdata();">搜索</a>
                    </td>
                    <td>
                        <a href="javascript:void(0);" class="easyui-linkbutton" iconcls="icon-clear" plain="true"
                            onclick="ui_loginlog_cleardata();">清空条件</a>
                    </td>
                </tr>
            </table>
        </div>
    </div>
    <div data-options="region:'center',border:false">
        <table id="ui_loginlog_dg" data-options="fit:true,border:false">
        </table>
    </div>
</div>
